package com.maccman.aireo.command
{
	/* add to controller
	addCommand( CreateAssetEvent.EVENT_CREATE_ASSET, CreateAssetCommand );
	*/
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.commands.ICommand;

	import com.maccman.aireo.model.AireoModelLocator;
	import com.maccman.aireo.control.CreateAssetEvent;

	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	
	import com.maccman.activeresource.Activeresource;
	import com.maccman.activeresource.IndexCollection;

	public class CreateAssetCommand implements ICommand, IResponder
	{
		public function execute(event:CairngormEvent):void
		{
		    var delegate : ActiveResource = new ActiveResource( "http://localhost:3000", "assets", this )
		    delegate.save(event.data)
		}
		
		public function result(data:Object):void
		{
		    var model = AireoModelLocator.getInstance()
		    model.assets.addItemAt(data, data.id)
		}
		
		public function fault(info:Object):void
		{
			var faultEvent :FaultEvent = FaultEvent( info )
			Alert.show( "fault at CreateAsset" )
		}
		
	}
}